package analyser.node.v2;

import analyser.node.AbstractNodeAnalyser;
import kit.AnalyserIndexerKit;
import kit.LetterIndexer;
import model.v2.smi.MibModuleIdentityNodeV2;
import util.common.CharType;
import util.common.MibKeys;
import util.common.StringUtils;

import java.util.List;

public class MibModuleIdentityV2Analyser extends AbstractNodeAnalyser<MibModuleIdentityNodeV2> {
    protected MibModuleIdentityNodeV2 node2;

    public MibModuleIdentityV2Analyser(List<String> txtList) {
        super(txtList);
        node = new MibModuleIdentityNodeV2();
        node2 = node;
    }

    @Override
    protected void doAnalyse( ){
        int state = 0;
        String str = null;
        String temp;
        String revision = null;
        char c;
        while (state != 99){
            switch (state){
                case 0:
                    str = indexer.getNextIgnoreLeftSpace(CharType.Number, CharType.Hyphen, CharType.Letter);
                    if (StringUtils.isNotNullOrWhiteSpace(str)){
                        this.node.name = str;
                        state = 1;
                    }else {
                        state = -99;
                    }
                    break;
                case 1:
                    state = kit.nextMatch(MibKeys.MODULE_IDENTITY, 2, -state);
                    break;
                case 2:
                    state = kit.nextMatch(MibKeys.LAST_UPDATED, 3, -state);
                    break;
                case 3:
                    c = indexer.probeNextCharIgnoreLeftSpace();
                    if (c == '#'){
                        this.node2.lastUpdated = this.extractAndAnalyseFormatText();
                        state = 4;
                    }else{
                        state = -state;
                    }
                    break;
                case 4:
                    state = kit.nextMatch(MibKeys.ORGANIZATION, 5, -state);
                    break;
                case 5:
                    c = indexer.probeNextCharIgnoreLeftSpace();
                    if (c == '#'){
                        this.node2.organization = this.extractAndAnalyseFormatText();
                        state = 6;
                    }else{
                        state = -state;
                    }
                    break;
                case 6:
                    state = kit.nextMatch(MibKeys.CONTACT_INFO, 7, -state);
                    break;
                case 7:
                    c = indexer.probeNextCharIgnoreLeftSpace();
                    if (c == '#'){
                        this.node2.contactInfo = this.extractAndAnalyseFormatText();
                        state = 8;
                    }else{
                        state = -state;
                    }
                    break;
                case 8:
                    state = kit.nextMatch(MibKeys.DESCRIPTION, 9, -state);
                    break;
                case 9:
                    c = indexer.probeNextCharIgnoreLeftSpace();
                    if (c == '#'){
                        this.node2.description = this.extractAndAnalyseFormatText();
                        state = 10;
                    }else{
                        state = -state;
                    }
                    break;
                case 10:
                    if ((state = kit.nextMatch(MibKeys.REVISION, 11, -10)) == 11){
                    }else if ((state = kit.nextMatch(MibKeys.ASSIGNMENT, 15, -10)) == 15){
                    }
                    break;
                case 11:
                    c = indexer.probeNextCharIgnoreLeftSpace();
                    if (c == '#'){
                        revision = this.extractAndAnalyseFormatText();
                        state = 12;
                    }else{
                        state = -state;
                    }
                    break;
                case 12:
                    state = kit.nextMatch(MibKeys.DESCRIPTION, 13, -state);
                    break;
                case 13:
                    c = indexer.probeNextCharIgnoreLeftSpace();
                    if (c == '#'){
                        str = this.extractAndAnalyseFormatText();
                        this.node2.revisionPart.add(new MibModuleIdentityNodeV2.Revision(revision, str));
                        state = 14;
                    }else{
                        state = -state;
                    }
                    break;
                case 14:
                    state = 10;
                    break;
                case 15:
                    analyseLeaf();
                    state = 99;
                    break;
                case 16: break;
                case 17: break;
                default:
                    kit.ThrowAnalysisException("解析MibModuleIdentityNodev2节点异常！", state, str);

            }
        }
        return;
    }

}
